package com.hst.capacity.infra.persistence.jpa.franchisee;

import com.hst.capacity.domain.model.entity.franchisee.FranchiseeEntity;
import com.hst.capacity.domain.model.response.franchisee.FranchiseRegionCodeVO;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface FranchiseRepository extends CrudRepository<FranchiseeEntity, String> {

    @Query("SELECT new com.hst.capacity.domain.model.response.franchisee.FranchiseRegionCodeVO(f.regionCode,s.name) FROM FranchiseeEntity f,SysRegionEntity s WHERE f.regionCode=s.code AND f.idFranchisee=?1")
    List<FranchiseRegionCodeVO> findByIdFranchisee(String idFranchisee);

    @Query("select f " +
            "from FranchiseeEntity f " +
            "inner join AirportEntity a on a.cityCode = f.regionCode " +
            "where f.regionCode = :regionCode")
    FranchiseeEntity findByRegionCode(String regionCode);

}
